<?php
/**
 * 数据列（column）管理
 * Created by PhpStorm.
 * User: ADKi
 * Date: 2016/8/26 0026
 * Time: 14:35
 * @author ADKi
 * @url http://lbsyun.baidu.com/index.php?title=lbscloud/api/geodata#.E6.95.B0.E6.8D.AE.E5.88.97.EF.BC.88column.EF.BC.89.E7.AE.A1.E7.90.86
 */

class column
{
    /**
     * 创建列（create column）接口
     * POST请求
     * */
    private $_create_column = 'http://api.map.baidu.com/geodata/v3/column/create';

    /**
     * 查询列（list column）接口
     * GET请求
     * */
    private $_list_column = 'http://api.map.baidu.com/geodata/v3/column/list';

    /**
     * 查询指定id列（detail column）详情接口
     * GET请求
     * */
    private $_detail_column = 'http://api.map.baidu.com/geodata/v3/column/detail';

    /**
     * 修改指定条件列（column）接口
     * POST请求
     * */
    private $_update_column = 'http://api.map.baidu.com/geodata/v3/column/update';

    /**
     * 删除指定条件列（column）接口
     * */
    private $_delete_column  = 'http://api.map.baidu.com/geodata/v3/column/delete';

    /**
     * 创建列
     * @param $send_data array
     * @return array
     * */
    public function PostCreate($send_data)
    {
        //初始化
        $form = curl_init();
        curl_setopt($form, CURLOPT_URL, $this->_create_column); //请求地址
        curl_setopt($form, CURLOPT_HEADER, false);  //没有头
        curl_setopt($form, CURLOPT_RETURNTRANSFER, true); //不直接输出到页面
        curl_setopt($form, CURLOPT_POST, true); //提交方式
        curl_setopt($form, CURLOPT_POSTFIELDS, $send_data); //提交数据
        $result = curl_exec($form);
        curl_close($form);
        return json_decode($result);
    }

    /**
     * 查询列
     * @param $send_data array
     * @return array
     * */
    public function GetList($send_data)
    {
        $url = $this->_list_column.'?'.http_build_query($send_data);
        $form = curl_init((string)$url);
        curl_setopt($form, CURLOPT_HEADER, false);
        curl_setopt($form, CURLOPT_RETURNTRANSFER, true); //不直接输出到页面
        $result = curl_exec($form);
        curl_close($form);
        return json_decode($result);
    }

    /**
     * 查询指定id列
     * @param $send_data array
     * @return array
     * */
    public function GetDetail($send_data)
    {
        $url = $this->_detail_column.'?'.http_build_query($send_data);
        $form = curl_init((string)$url);
        curl_setopt($form, CURLOPT_HEADER, false);
        curl_setopt($form, CURLOPT_RETURNTRANSFER, true); //不直接输出到页面
        $result = curl_exec($form);
        curl_close($form);
        return json_decode($result);
    }

    /**
     * 修改指定条件列
     * @param $send_data array
     * @return array
     * */
    public function PostUpdate($send_data)
    {
        //初始化
        $form = curl_init();
        curl_setopt($form, CURLOPT_URL, $this->_update_column); //请求地址
        curl_setopt($form, CURLOPT_HEADER, false);  //没有头
        curl_setopt($form, CURLOPT_RETURNTRANSFER, true); //不直接输出到页面
        curl_setopt($form, CURLOPT_POST, true); //提交方式
        curl_setopt($form, CURLOPT_POSTFIELDS, $send_data); //提交数据
        $result = curl_exec($form);
        curl_close($form);
        return json_decode($result);
    }

    /**
     * 删除指定条件列
     * @param $send_data array
     * @return array
     * */
    public function GetDelete($send_data)
    {
        $url = $this->_delete_column.'?'.http_build_query($send_data);
        $form = curl_init((string)$url);
        curl_setopt($form, CURLOPT_HEADER, false);
        curl_setopt($form, CURLOPT_RETURNTRANSFER, true); //不直接输出到页面
        $result = curl_exec($form);
        curl_close($form);
        return json_decode($result);
    }
}